package com.didibigdata.servlets;

import com.didibigdata.Repositories.PointOutReadSizeRepository;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashSet;
import java.util.Set;

@WebServlet("/PointOutServletReadSize")
public class PointOutServletReadSize extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String sqltime = "select * from t_didi201610_train_out_200m_day1_2to4 order by timestp";
        PointOutReadSizeRepository pointOutReadSizeRepository = new PointOutReadSizeRepository();
        int orderSetSize = pointOutReadSizeRepository.getPointOutReadSize(sqltime);
        ObjectMapper mapper = new ObjectMapper();
        String jsonSize = mapper.writeValueAsString(orderSetSize);
        response.setContentType("text/html; charset=utf-8");
        response.getWriter().write(jsonSize);
    }
}
